package cn.zn.log.service.impl;

import cn.zn.log.entity.SysLoginRecord;
import cn.zn.log.mapper.SysLoginRecordMapper;
import cn.zn.log.service.SysLoginRecordService;
import cn.zn.log.vo.SysLoginRecordPageVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zn-admin
 * @since 2021-01-28
 */
@Service
public class SysLoginRecordServiceImpl extends ServiceImpl<SysLoginRecordMapper, SysLoginRecord> implements SysLoginRecordService {

    @Override
    public void insertLoginRecord(SysLoginRecord loginRecord) {
        baseMapper.insert(loginRecord);
    }

    @Override
    public Object selectLoginRecordList(SysLoginRecordPageVo vo) {
        if (!vo.getPage()) {
            return baseMapper.selectLoginRecordList(vo);
        }

        Page<SysLoginRecord> page = new Page<>(vo.getCurrent(), vo.getSize());
        return baseMapper.selectLoginRecordList(page, vo);
    }

    @Override
    @Transactional
    public void deleteLoginRecordByIds(String[] infoIds) {
        baseMapper.deleteBatchIds(Arrays.asList(infoIds));
    }

    @Override
    public void cleanLoginRecord() {
        baseMapper.cleanLoginRecord();
    }

}
